package com.jzr.bedside.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jzr.bedside.db1.model.TDoctorOrder;
import com.jzr.bedside.db1.service.TDoctorOrderService;
import com.jzr.common.entity.vo.Result;
import com.jzr.common.util.U;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("医嘱接口")
@RestController
@RequestMapping("/api/doctorOrder")
public class DoctorOrderController {
    @Autowired
    private TDoctorOrderService doctorOrderService;

    @ApiOperation("获取医嘱列表")
    @GetMapping("/get")
    public Result<List<TDoctorOrder>> get(@ApiParam("医嘱查询参数") TDoctorOrder record){
        if(record.getPatientCode() == null){
            return Result.fail("patientCode不能为空");
        }
        QueryWrapper<TDoctorOrder> qw = new QueryWrapper<>();
        qw.orderByAsc("patient_code","patient_cure_no","group_code","drug_code");
        if(U.isNotBlank(record.getPatientCode())) {
            qw.eq(TDoctorOrder.PatientCode_,record.getPatientCode());
        }
        if(U.isNotBlank(record.getPatientCureNo())){
            qw.eq(TDoctorOrder.PatientCureNo_,record.getPatientCureNo());
        }

        List<TDoctorOrder> list = doctorOrderService.list(qw);
        return Result.success("成功",list,list==null ? 0:list.size());
    }

}
